<template>
	<!-- 装配检验 -->
	<div>
		<v-container row class="text-subtitle-1 d-flex justify-center  align-left">

			<v-divider class="mx-4" inset vertical></v-divider>
			<v-row class="mt-2">
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目号" v-model="assemblyQuery.projectCode" placeholder="项目号" dense outlined>
					</v-text-field>
				</v-col>
				<!-- sm="6" md="2" -->
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="项目名称" v-model="assemblyQuery.projectName" placeholder="项目名称" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="3" md="2">
					<v-text-field label="设备名称" v-model="assemblyQuery.equipmentName" placeholder="设备名称" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="2" md="2">
					<v-text-field label="工单号" v-model="assemblyQuery.childrenCode" placeholder="工单号" dense outlined>
					</v-text-field>
				</v-col>
				<v-col cols="12" sm="2" md="2">
					<v-select   outlined
						v-model="assemblyQuery.readyorbulk" :items="readyorbulks"
						dense label="选择整装或散装">
					</v-select>
				</v-col>
				<!-- ml-n16 前面加n是间距 -->
				<!-- class="ml-n16 mx-auto" -->
				<v-col cols="12" sm="2" md="2">
					<v-btn depressed color="primary" @click="assemblyQueryLoad">查询</v-btn>
					<v-btn class="ml-3" depressed color="primary" @click="refreshassemblyQueryLoad">
						刷新</v-btn>
				</v-col>
			</v-row>
		</v-container>
		<br />
		<!-- :single-select="true" -->
		<v-data-table :headers="assemblyHeader" :items="assemblyDataList" small fixed-header item-key="id" dense
			class="text-no-wrap" loading-text="正在加载请稍等......" :options.sync="assemblyOptions"
			:footer-props="vuetifyDefaultPage" :loading="assemblyLoading" :server-items-length="assemblyTotalCount">
			<template v-slot:item.checkstatus="{ item }">
				<a v-if="item.checkstatus" style="color: #67C23A;">检验完成</a>
				<a v-else>未完成</a>
			</template>
			<template v-slot:item.actions="{ item }">
				<div>
					<v-btn  small tile color="primary" :disabled="item.checkstatus"
						@click="openassemblyDetailDialog(item)">
						录入检验信息
					</v-btn>
					<v-btn class="ml-2" small tile color="primary" @click="openLabelDialog(item)">
						列印设备标签
					</v-btn>

					<v-btn class="ml-2" small tile color="primary" @click="openExceptionDialog(item)">
						录入异常信息
					</v-btn>
				</div>
			</template>
		</v-data-table>

		<!-- 检验对话框 -->
		<assemblycheckedit :checkInfo="checkInfo" :callBackLoadProcessCards="assemblyQueryLoad"></assemblycheckedit>
		<!-- 异常信息对话框 -->
		<andonoperation :activeAndonDialogModel="activeAndonDialogModel"></andonoperation>
		<printequilabel :labelModel="labelModel"></printequilabel>
	</div>
</template>

<script>
	import andonoperation from '../components/andon/andon_add.vue'
	import assemblycheckedit from '../components/assembly_check/assembly_check_edit.vue'
	import PrintEquiLabel from '../components/assembly_check/PrintEquiLabel.vue'
	import {
		mapActions
	} from 'vuex'
	export default {
		name: 'assembly_check',
		components: {
			andonoperation,
			assemblycheckedit,
			printequilabel:PrintEquiLabel
		},
		data() {
			return {
				labelModel: {
					dialog: false,
					//零件终检验id
					childrenId:0
				},
				readyorbulks: ['整装', '散装'],
				activeAndonDialogModel: {
					andonOperationDialog: false,
					childrenid: 0,
					controllerName:''
				},
				//检验信息
				checkInfo: {
					cardModel: {},
					assemblyCheckEditDialog: false,
				},
				assemblyQuery: {
					projectCode: '',
					projectName: '',
					equipmentName: '',
					childrenCode: ''
				},
				assemblyHeader: [],
				assemblyDataList: [],
				assemblyOptions: { //页数
					page: 1,
					//每页行数
					itemsPerPage: 10
				},
				assemblyLoading: true,
				assemblyTotalCount: 0,
				vuetifyDefaultPage: {
					'items-per-page-text': '每页个数',
					'items-per-page-options': [10, 20, 50, 100]
					// 'items-per-page-all-text': '100'
				},
			}
		},
		created() {
			this.GetHeader()
		},
		watch: {
			assemblyOptions: {
				handler() {
					this.assemblyQueryLoad()
				},
				deep: true
			},
		},
		methods: {
			...mapActions('mes/assembly_check', [
				'LoadAssemblyList'
			]),
			async assemblyQueryLoad() {
				this.assemblyLoading = true
				var response = await this.LoadAssemblyList({
					projectCode: this.assemblyQuery.projectCode,
					projectName: this.assemblyQuery.projectName,
					equipmentName: this.assemblyQuery.equipmentName,
					childrenCode: this.assemblyQuery.childrenCode,
					readyorbulk:this.assemblyQuery.readyorbulk,
					type: 20,
					pageNumber: this.assemblyOptions.page,
					pageSize: this.assemblyOptions.itemsPerPage
				})
				if (response.status == 1) {
					this.assemblyDataList = response.data.result
					this.assemblyTotalCount = response.data.pagination.totalRecords
					this.assemblyLoading = false
				}else
				{
					this.$message.error(response.info)
				}
			},
			refreshassemblyQueryLoad() {
				this.assemblyQuery = {
					projectCode: '',
					projectName: '',
					equipmentName: '',
					childrenCode: ''
				}
				this.assemblyQueryLoad()

			},

			openassemblyDetailDialog(assemblyModel) {
				this.checkInfo.cardModel = assemblyModel.processCard
				this.checkInfo.assemblyCheckEditDialog =true
			},


			cannel() {
				this.currentClickassemblyDetailModel = {}
				this.addassemblyDetailListDialog = false
				this.printQADialog = false
			},
			//打开录入错误信息对话框
			async openExceptionDialog(item) {
				this.activeAndonDialogModel.andonOperationDialog = true
				this.activeAndonDialogModel.childrenid = item.childrenorderid
				this.activeAndonDialogModel.controllerName='MESQaAssembly'
			},


			//列印标签对话框 TODO
			openLabelDialog(item) {
          this.labelModel.dialog=true
					this.labelModel.childrenId=item.processCard.childrenOrder.id
			},
			GetHeader() {
				this.assemblyHeader = [{
						text: '操作',
						align: 'center',
						value: 'actions',
						filterable: false,
						class: 'fixed'
					},
					{
							text: '是否检验完成',
							align: 'center',
							value: 'checkstatus',
							filterable: false,
							class: 'fixed'
						},
					{
						text: '项目号',
						align: 'center',
						value: 'projectcode',
						filterable: false,
						class: 'fixed'
					}, {
						text: '项目名称',
						align: 'center',
						value: 'projectname',
						filterable: false,
						class: 'fixed'
					}, {
						text: '设备名称',
						align: 'center',
						value: 'equname',
						filterable: false,
						class: 'fixed'
					}, {
						text: '设备图号',
						align: 'center',
						value: 'piccode',
						filterable: false,
						class: 'fixed'
					}, {
						text: '设备型号',
						align: 'center',
						value: 'equmodel',
						filterable: false,
						class: 'fixed'
					}, 
					{
						text: '整装/散装',
						align: 'center',
						value: 'readyorbulk',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '类型',
						align: 'center',
						value: 'typename',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '数量',
						align: 'center',
						value: 'qty',
						filterable: false,
						class: 'fixed'
					}, {
						text: '设计人',
						align: 'center',
						value: 'designer',
						filterable: false,
						class: 'fixed'
					}, {
						text: '装配人',
						align: 'center',
						value: 'assemblyer',
						filterable: false,
						class: 'fixed'
					}, {
						text: '检测人',
						align: 'center',
						value: 'checkuser',
						filterable: false,
						class: 'fixed'
					}, {
						text: '检查数量',
						align: 'center',
						value: 'checkqty',
						filterable: false,
						class: 'fixed'
					}, {
						text: '检测日期',
						align: 'center',
						value: 'checkdate',
						filterable: false,
						class: 'fixed'
					},
				];
			}
		},
	}
</script>
